package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.OrderInfo;
import com.ruoyi.system.service.IOrderInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 景点门票订单信息Controller
 * 
 * @author ruoyi
 * @date 2025-06-03
 */
@RestController
@RequestMapping("/system/infos")
public class OrderInfoController extends BaseController
{
    @Autowired
    private IOrderInfoService orderInfoService;

    /**
     * 查询景点门票订单信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrderInfo orderInfo)
    {
        startPage();
        List<OrderInfo> list = orderInfoService.selectOrderInfoList(orderInfo);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('system:info:list')")
    @GetMapping("/list1")
    public TableDataInfo list1(@RequestParam("userId") Integer uid)
    {
        startPage();
        List<OrderInfo> list = orderInfoService.selectOrderInfoList1(uid);
        return getDataTable(list);
    }

    /**
     * 导出景点门票订单信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:export')")
    @Log(title = "景点门票订单信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderInfo orderInfo)
    {
        List<OrderInfo> list = orderInfoService.selectOrderInfoList(orderInfo);
        ExcelUtil<OrderInfo> util = new ExcelUtil<OrderInfo>(OrderInfo.class);
        util.exportExcel(response, list, "景点门票订单信息数据");
    }

    /**
     * 获取景点门票订单信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(orderInfoService.selectOrderInfoById(id));
    }

    /**
     * 新增景点门票订单信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:add')")
    @Log(title = "景点门票订单信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderInfo orderInfo)
    {
        return toAjax(orderInfoService.insertOrderInfo(orderInfo));
    }

    /**
     * 修改景点门票订单信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:edit')")
    @Log(title = "景点门票订单信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderInfo orderInfo)
    {
        return toAjax(orderInfoService.updateOrderInfo(orderInfo));
    }

    /**
     * 删除景点门票订单信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:remove')")
    @Log(title = "景点门票订单信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(orderInfoService.deleteOrderInfoByIds(ids));
    }

    /**
     * 根据用户ID查询订单信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:list')")
    @GetMapping("/user/{uid}")
    public AjaxResult getByUid(@PathVariable("uid") Integer uid) {
        // 添加日志查看传入的uid是否正确
        logger.info("查询用户ID为 {} 的订单", uid);
        List<OrderInfo> orders = orderInfoService.selectOrderInfoByUid(uid);
        // 添加日志查看查询结果
        logger.info("查询结果数量: {}", orders.size());
        return success(orders);
    }
}
